'GOST 6364

'GCV_FRONT = 2
'GCV_LEFT = 4
'GCV_RIGHT = 5
'GCV_EXTENDED = 7
'GCV_SIMPLIFIED = 8
'GCV_STANDARD = 9
'SIDE = GCV_FRONT

'DETAIL_LEVEL = GCV_STANDARD

hatchAngle  = 45                  
'hatchStep= 2   

'PAR_din=130
'PAR_D=180
'PAR_T=75
'PAR_B=30
'PAR_C=62
'PAR_r=2.5
'PAR_r1=0.8

din2= PAR_din/2
D2= PAR_D/2
H=D2-din2
b1= PAR_T/2-PAR_B'PAR_T *0.09
b2= PAR_T /2
C2=PAR_C/2
xr1= b1+PAR_B*0.1
yr1= din2+H*0.4
alfa=10
ralfa=alfa*3.1416/180
Dw2=H*0.2
Lw=(C2-xr1)/cos(ralfa)
DWb2= Dw2+Lw*sin(ralfa/2)
xr2= xr1+Lw*cos(ralfa)
yr2= yr1+Lw*sin(ralfa)
bb2= xr2+DWb2*sin(ralfa)
dinb2= yr2-DWb2*cos(ralfa)
r= PAR_r
r1= PAR_r1
dinn2=yr2
tx= xr1-Dw2*sin(ralfa)
ty= yr1+Dw2*cos(ralfa)
tx2= xr2-DWb2*sin(ralfa)
ty2= yr2+DWb2*cos(ralfa)
Db2= ty2+(C2-tx2)*tan(ralfa*1.5)
Dv2= ty-tx*tan(ralfa*1.5)


'++++++++++++++++++++
SUB LINE (x1,y1,x2,y2,t) 
Doc.ksLineSEG x1,y1,x2,y2,t 
END SUB
'++++++++++++++++++++
SUB ARC (xc,yc,r,x1,y1,x2,y2,n,s)
Doc.ksArcByPoint xc,yc,r,x1,y1,x2,y2,n,s
END SUB
'++++++++++++++++++++

SUB Script_OnLoad ()

Doc.ksColouring &HFE000000
 inside_app 1,1
 inside_app 1,-1 
 inside_app -1,1
 inside_app -1,-1

 outside_app 1,1
 outside_app 1,-1
 outside_app -1,1
 outside_app -1,-1
doc.ksEndObj

Select Case DETAIL_LEVEL
       Case GCV_EXTENDED:

Inside_ring 1,1
Inside_ring 1,-1
Inside_ring -1,1
Inside_ring -1,-1



Roller 1,1
Roller 1,-1
Roller -1,1
Roller -1,-1

Outside_ring 1,1
Outside_ring 1,-1
Outside_ring -1,1
Outside_ring -1,-1

Bushing 1,1
Bushing 1,-1
Bushing -1,1
Bushing -1,-1

      Case  GCV_STANDARD:
Inside_ring 1,1
Inside_ring -1,1



Roller 1,1
Roller -1,1

Outside_ring 1,1
Outside_ring -1,1

Bushing 1,1
Bushing -1,1

DrawSimple  -1,-1
DrawSimple  1,-1
      Case  GCV_SIMPLIFIED:

    DrawSimple  1,1
    DrawSimple  -1,1  
      
    DrawSimple  -1,-1
    DrawSimple  1,-1  
      End Select 

If PAR_AXIS = 1 Then 
 Line -PAR_T/2-2,0, PAR_T/2+2,0,3
End If 
END SUB
'++++++++++++++++++++
SUB Inside_ring (orient_h,orient_v)
oh =orient_h
ov =orient_v

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF

Line b1*oh,dinb2*ov,b1*oh,(din2+r)*ov, 1
Arc (b1+r)*oh,(din2+r)*ov,r, b1*oh,(din2+r)*ov, (b1+r)*oh, din2*ov,napv,1
Line (b1+r)*oh, din2*ov, (b2-r)*oh, din2*ov,1
Arc (b2-r)*oh, (din2+r)*ov,r, (b2-r)*oh, din2*ov, b2*oh, (din2+r)*ov, napv,1
Line b2*oh, (din2+r)*ov, b2*oh,(dinn2-r)*ov,1
Arc (b2-r)*oh, (dinn2-r)*ov,r, b2*oh,(dinn2-r)*ov, (b2-r)*oh, dinn2*ov, napv,1
'Line (b2-r)*oh, dinn2*ov,bb2*oh, dinn2*ov,1
Line (b2-r)*oh, dinn2*ov,xr2*oh, dinn2*ov,1
'Line bb2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
Line xr2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
Line bb2*oh, dinb2*ov,(xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov,1

t= yr1-dinb2 
xper=xr1+t*tan(ralfa)

Line (xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov, xper*oh, dinb2*ov,1
Line xper*oh, dinb2*ov, b1*oh,dinb2*ov,1

Doc.kshatch  0, hatchAngle-90, hatchStep, 0, 0, 0   
Line b1*oh,(din2+r)*ov,b1*oh,dinb2*ov,1
Arc (b1+r)*oh,(din2+r)*ov,r, b1*oh,(din2+r)*ov, (b1+r)*oh, din2*ov,napv,1
Line (b1+r)*oh, din2*ov, (b2-r)*oh, din2*ov,1
Arc (b2-r)*oh, (din2+r)*ov,r, (b2-r)*oh, din2*ov, b2*oh, (din2+r)*ov, napv,1
Line b2*oh, (din2+r)*ov, b2*oh,(dinn2-r)*ov,1
Arc (b2-r)*oh, (dinn2-r)*ov,r, b2*oh,(dinn2-r)*ov, (b2-r)*oh, dinn2*ov, napv,1
'Line (b2-r)*oh, dinn2*ov,bb2*oh, dinn2*ov,1
'Line bb2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
Line (b2-r)*oh, dinn2*ov,xr2*oh, dinn2*ov,1
Line xr2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
Line bb2*oh, dinb2*ov,(xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov,1
Line (xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov, xper*oh, dinb2*ov,1
Line xper*oh, dinb2*ov, b1*oh,dinb2*ov,1
Doc.ksEndObj
If par_axis = 1 Then 
Line b1*oh,(din2+r)*ov, b1*oh,0,1
Line (b1+r)*oh, din2*ov, (b1+r)*oh,0,1
Line (b2-r)*oh, din2*ov, (b2-r)*oh,0,1
Line b2*oh,(dinn2-r)*ov, b2*oh,0,1
End If 
END SUB

'+++++++++++++++++++++++++
SUB Roller (oh,ov) 
Line (xr1-2*cos(ralfa))*oh, (yr1-2*sin(ralfa))*ov, (xr2+2*cos(ralfa))*oh,(yr2+2*sin(ralfa))*ov,3

Line (xr1+Dw2*sin(ralfa))*oh, (yr1-Dw2*cos(ralfa))*ov, (xr1-Dw2*sin(ralfa))*oh, (yr1+Dw2*cos(ralfa))*ov,1
Line (xr1-Dw2*sin(ralfa))*oh, (yr1+Dw2*cos(ralfa))*ov, (xr2-DWb2*sin(ralfa))*oh, (yr2+DWb2*cos(ralfa))*ov,1
Line (xr2-DWb2*sin(ralfa))*oh, (yr2+DWb2*cos(ralfa))*ov, (xr2+DWb2*sin(ralfa))*oh, (yr2-DWb2*cos(ralfa))*ov,1


END SUB
'++++++++++++++++++++++++++++

SUB Outside_ring (oh,ov)

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF


Line 0,D2*ov, (C2-r1)*oh, D2*ov,1
Arc (C2-r1)*oh,(D2-r1)*ov,r1, (C2-r1)*oh, D2*ov, C2*oh, (D2-r1)*ov, -napv,1
Line C2*oh, (D2-r1)*ov, C2*oh,Db2*ov,1
Rd=(D2-Dv2)*cos(ralfa*1.5)
xd=Rd*sin(ralfa*1.5)
yd=Rd*cos(ralfa*1.5)
Line C2*oh,Db2*ov, xd*oh,(D2-yd)*ov,1
Arc 0,D2*ov,Rd,xd*oh,(D2-yd)*ov,0,(D2-Rd)*ov,-napv,1

Doc.kshatch  0, hatchAngle, hatchStep, 0, 0, 0   
Line 0,D2*ov, (C2-r1)*oh, D2*ov,1
Arc (C2-r1)*oh,(D2-r1)*ov,r1, (C2-r1)*oh, D2*ov, C2*oh, (D2-r1)*ov, -napv,1
Line C2*oh, (D2-r1)*ov, C2*oh,Db2*ov,1
Line C2*oh,Db2*ov, xd*oh,(D2-yd)*ov,1
Arc 0,D2*ov,Rd,xd*oh,(D2-yd)*ov,0,(D2-Rd)*ov,-napv,1
Line 0,(D2-Rd)*ov, 0,D2*ov,1
Doc.ksEndObj

Line C2*oh,Db2*ov,C2*oh,(yr2+(xr2-C2)/tan(ralfa))*ov,1
END SUB
              
'++++++++++++++++++++++++
SUB Bushing (oh,ov)

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF


Line 0,(dinb2-H*0.05)*ov,b1*oh, (dinb2-H*0.05)*ov,1
Line b1*oh, (dinb2-H*0.05)*ov, b1*oh, (din2+r)*ov,1
Arc (b1-r)*oh, (din2+r)*ov,r, b1*oh, (din2+r)*ov, (b1-r)*oh, din2*ov, -napv,1
Line (b1-r)*oh, din2*ov,0, din2*ov,1

Doc.kshatch  0, hatchAngle, hatchStep/2, 0, 0, 0   
Line 0,(dinb2-H*0.05)*ov,b1*oh, (dinb2-H*0.05)*ov,1
Line b1*oh, (dinb2-H*0.05)*ov, b1*oh, (din2+r)*ov,1
Arc (b1-r)*oh, (din2+r)*ov,r, b1*oh, (din2+r)*ov, (b1-r)*oh, din2*ov, -napv,1
Line (b1-r)*oh, din2*ov,0, din2*ov,1
Line 0, din2*ov, 0,(dinb2-H*0.05)*ov,1
Doc.ksEndObj
If PAR_AXIS = 1 Then 
Line b1*oh, (din2+r)*ov, b1*oh, 0,1
Line (b1-r)*oh, din2*ov, (b1-r)*oh,0,1
End If 
End SUB

'+++
Sub CONTUR
End Sub
'+++
Sub inside_app(orient_h,orient_v)
oh =orient_h
ov =orient_v

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF

Line b2*oh, (din2+r)*ov, b2*oh,(dinn2-r)*ov,1
Arc (b2-r)*oh, (dinn2-r)*ov,r, b2*oh,(dinn2-r)*ov, (b2-r)*oh, dinn2*ov, napv,1
Line (b2-r)*oh, dinn2*ov,xr2*oh, dinn2*ov,1
Line b2*oh,(dinn2-r)*ov, b2*oh,0,1
End Sub
'+++
Sub outside_app(oh,ov)

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF

Line 0,D2*ov, (C2-r1)*oh, D2*ov,1
Arc (C2-r1)*oh,(D2-r1)*ov,r1, (C2-r1)*oh, D2*ov, C2*oh, (D2-r1)*ov, -napv,1
Line C2*oh, (D2-r1)*ov, C2*oh,Db2*ov,1
Line C2*oh,Db2*ov,C2*oh,(yr2+(xr2-C2)/tan(ralfa))*ov,1
End Sub
'+++
 '+++++++++++++++++++++
sub DrawSimple (orient_h,orient_v)
oh =orient_h
ov =orient_v

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF

'''Line b1*oh,dinb2*ov,b1*oh,(din2+r)*ov, 1
'Arc (b1+r)*oh,(din2+r)*ov,r, b1*oh,(din2+r)*ov, (b1+r)*oh, din2*ov,napv,1
''Line (b1+r)*oh, din2*ov, (b2-r)*oh, din2*ov,1
'''
Line (b1+r)*oh, din2*ov, (b2-r)*oh, din2*ov,1
Line (b1+r)*oh, din2*ov, 0, din2*ov,1
'''
Arc (b2-r)*oh, (din2+r)*ov,r, (b2-r)*oh, din2*ov, b2*oh, (din2+r)*ov, napv,1
Line b2*oh, (din2+r)*ov, b2*oh,(dinn2-r)*ov,1
Arc (b2-r)*oh, (dinn2-r)*ov,r, b2*oh,(dinn2-r)*ov, (b2-r)*oh, dinn2*ov, napv,1

'''''Line (b2-r)*oh, dinn2*ov,bb2*oh, dinn2*ov,1
Line (b2-r)*oh, dinn2*ov,xr2*oh, dinn2*ov,1
''''''Line bb2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
''Line xr2*oh, dinn2*ov, bb2*oh, dinb2*ov,1
''Line bb2*oh, dinb2*ov,(xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov,1

t= yr1-dinb2 
xper=xr1+t*tan(ralfa)

'Line (xr1+Dw2*sin(ralfa))*oh,(yr1-Dw2*cos(ralfa))*ov, xper*oh, dinb2*ov,1
'Line xper*oh, dinb2*ov, b1*oh,dinb2*ov,1



If par_axis = 1 Then 
''Line b1*oh,(din2+r)*ov, b1*oh,0,1
''Line (b1+r)*oh, din2*ov, (b1+r)*oh,0,1
Line (b2-r)*oh, din2*ov, (b2-r)*oh,0,1
Line b2*oh,(dinn2-r)*ov, b2*oh,0,1
End If 

'+++++++
oh = orient_h
ov = orient_v

IF oh=ov THEN
napv=1 
ELSE
napv=-1 END IF


Line 0,D2*ov, (C2-r1)*oh, D2*ov,1
Arc (C2-r1)*oh,(D2-r1)*ov,r1, (C2-r1)*oh, D2*ov, C2*oh, (D2-r1)*ov, -napv,1
Line C2*oh, (D2-r1)*ov, C2*oh,Db2*ov,1
Rd=(D2-Dv2)*cos(ralfa*1.5)
xd=Rd*sin(ralfa*1.5)
yd=Rd*cos(ralfa*1.5)
''Line C2*oh,Db2*ov, xd*oh,(D2-yd)*ov,1
''Arc 0,D2*ov,Rd,xd*oh,(D2-yd)*ov,0,(D2-Rd)*ov,-napv,1


Line C2*oh,Db2*ov,C2*oh,(yr2+(xr2-C2)/tan(ralfa))*ov,1
'+++++++


  If PAR_Simpl_AXIS = 1 Then 
    Line -(C2-r1)*oh,(D2-r1)*ov,(b2-r)*oh, (din2+r)*ov,2
   ''NEW 
   Else 
   Delta = (D2-din2)*ov/3
    Line 0, din2*ov+delta, 0, D2*ov-delta,2
    Line 0,(D2+din2)*ov/2,Delta*oh/2,(D2+din2)*ov/2,2
   ''
  End If  

end sub
'+++++++++++++++